<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绝对定位水平垂直居中</title>
    <style>
        .box {
            position: absolute;
            /*1. left走50%，父容器宽度的一半 */
            left: 50%;
            /* 2.margin 负值 往左边走自己盒子宽度的一半 */
            margin-left: -100px;
            top:50%;
            margin-top: -100px;
            height: 200px;
            width: 200px;
            background-color: pink;

        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>

</html>